
import {
    Platform,
} from 'react-native';

import AndroidModule from './AndroidConnent'
import OpenIMSDKRN from "open-im-sdk-rn";
import Constant from '../utils/Constant'//全局变量
import ToastToUser from '../utils/CustomToast'

const isIos = Platform.OS == 'ios';

export default (result,resolve,errorResponse) => {
    if (result.code == -113) {//session失效
        try {
            OpenIMSDKRN.logout(Constant.userInfo.username)
            .then(() => {
                ToastToUser('退出登录成功')
                if (isIos) {
                    OpenIMSDKRN.unInitSDK(Constant.userInfo.username).then(() => {
                        console.log('unInitSDK成功')
                    })
                        .catch(({ errCode, errMsg }) => {
                            // unInitSDK失败
                            console.log('unInitSDK失败')
                        });
                }
                
            })
            .catch(({ errCode, errMsg }) => {
                // 调用失败
                // ToastToUser('退出登录失败')
                if (isIos) {
                    OpenIMSDKRN.unInitSDK(Constant.userInfo.username).then(()=> {
                        console.log('unInitSDK成功')
                    })
                    .catch(({ errCode, errMsg }) => {
                        // unInitSDK失败
                        console.log('unInitSDK失败')
                    });
                }
            });
            setTimeout(() => {
                AndroidModule.sessionExpired()
            }, 3000);
        }catch (error) {
            console.log('error = ',error)
        }
        
            
    } else {
        resolve(result)
    }

}